#ifndef PLCCONNECTER_H
#define PLCCONNECTER_H

#include <QObject>
#include "string"

#define PLCCONNECTER HIM::PlcConnecter::getInstance()

using namespace std;

class ModbusTCP;

namespace HIM{

class PlcConnecter : public QObject
{
    Q_OBJECT

public:
    static PlcConnecter& getInstance(){
        static PlcConnecter instance;
        return instance;
    }

    bool startConnect(string ip,uint16_t port,int slave_id);
    bool stopConnect();
    bool reConnect(string ip,uint16_t port,int slave_id);
    bool getConnectStatus();
    bool readRegisters(int addr, int nb, uint16_t  *dest);
    bool writeRegisters(int addr, int nb, uint16_t  *dest);

    float getFloatFromDDByte(uint16_t *dest);
    void setFloatFromDDByte(float src,uint16_t *dest);

private:
    PlcConnecter();
    ~PlcConnecter();

    PlcConnecter(const PlcConnecter&)=delete ;
    PlcConnecter& operator=(const PlcConnecter&)=delete ;

private:
    ModbusTCP *plcCon;
    bool plcConnectStatus{false};
};
}

#endif // PLCCONNECTER_H
